var layerLoad;

/**
 * 页面初始化加载
 */
(function(){
	initProductList(1);
})();
function initProductList(currentPage){
	$.ajax({
		url : $api.member.selectMembers,
		type : "POST",
		dataType : "JSON",
		contentType : 'application/json',
		data : JSON.stringify({"currentPage" : currentPage}),
		beforeSend : function () {
			layerLoad = layer.load();
		},
		success : function(data) {
			console.log(data)
			if(!$checkRemouteStatus(data)){
				layer.close(layerLoad);
				return;
			}
			layui.use('laytpl', function() {
				var laytpl = layui.laytpl;
				laytpl(sysProductListTpl.innerHTML).render(data, function(html) {
					$('#system-member-list-body-page').html(html);
				});
			});
			layui.use('laypage', function() {
				layui.laypage({
					cont: $('#sys-member-list-body-page'),
					pages: data.totalPage,
					groups: 2,
					curr: data.currentPage,
					skip: true,
                    skin:'#0e90d2',
					jump: function (obj,first) {
						if(!first){
                            initProductList(obj.curr);
						}
					}
				});
			});
			layer.close(layerLoad);
		},
		error : function() {
			layer.close(layerLoad);
			layer.msg('网络异常，请稍后再试', {icon: 2});
		}
	});
};


/**
 * 搜索
 */
$('#sys-product-form-list-search').submit(function(e){
	e.preventDefault();
	//initOrderList(1);
});

/*详情*/
var memberId="";
var layerNumber="";
function edit(othis){
    memberId=$(othis).attr("memberId");
    $.ajax({
        url: $api.member.selectMemberById + "?memberId=" + memberId,
        type: "GET",
        dataType: "JSON",
        contentType : 'application/json',
        beforeSend: function () {
            layerLoad = layer.load();
        },
        success: function (data) {
        	layer.close(layerLoad);
        	var dataObj=data.msg;
            if(data.code == '111111'){
                layer.msg(data.msg, {icon: 2});
            }else{
                $("#systemMemberName").val(dataObj.name);
            	$("#systemMemberLoginIp").val(dataObj.loginIp);
            	$("#systemMemberCreateDate").val(dataObj.createDate);
            	$("#systemMemberEmail").val(dataObj.email);
                layerNumber = layer.open({
                    type : 1,
                    title : '会员信息详情',
                    area : 'auto',
                    maxWidth : '1000px',
                    content : $('#system-member-update-model'),
                    cancel : function(){
                    }
                });
            	//dataObj.postType==1?$("#postType option").eq(1).attr("selected",true):$("#postType option").eq(2).attr("selected",true);
            }
        },
        error: function () {
        	layer.msg("网络开小差啦", {icon: 2});
        }
    });
}
$("#modelClose").click(function(){
    layer.close(layerNumber);
    $("#system-member-update-model input").each(function(index,dom){
        $(dom).val("");
    });
});

